/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.persistence.entities;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author clayton
 */
@Entity 
@Table(name = "tags")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Tags.findAll", query = "SELECT t FROM Tags t"),
    @NamedQuery(name = "Tags.findByKungkhieId", query = "SELECT t FROM Tags t WHERE t.tagsPK.kungkhieId = :kungkhieId"),
    @NamedQuery(name = "Tags.findByTag", query = "SELECT t FROM Tags t WHERE t.tagsPK.tag = :tag")
})
public class Tags implements Serializable 
{
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TagsPK tagsPK;
    @JoinColumn(name = "kungkhie_id", referencedColumnName = "kungkhie_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Kungkhie kungkhie;

    public Tags()
    {
    }

    public Tags(TagsPK tagsPK)
    {
        this.tagsPK = tagsPK;
    }

    public Tags(long kungkhieId, String tag)
    {
        this.tagsPK = new TagsPK(kungkhieId, tag);
    }

    public TagsPK getTagsPK()
    {
        return tagsPK;
    }

    public void setTagsPK(TagsPK tagsPK)
    {
        this.tagsPK = tagsPK;
    }

    public Kungkhie getKungkhie()
    {
        return kungkhie;
    }

    public void setKungkhie(Kungkhie kungkhie)
    {
        this.kungkhie = kungkhie;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (tagsPK != null ? tagsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Tags))
        {
            return false;
        }
        Tags other = (Tags) object;
        if ((this.tagsPK == null && other.tagsPK != null) || (this.tagsPK != null && !this.tagsPK.equals(other.tagsPK)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "com.kungkhies.persistence.entities.Tags[ tagsPK=" + tagsPK + " ]";
    }

}
